package org.boulderfoodrescue.webapp.client.events;

import org.boulderfoodrescue.webapp.shared.UserAccountDetails;

import com.allen_sauer.gwt.log.client.Log;
import com.google.gwt.event.shared.GwtEvent;

public class UsersListUpdatedEvent extends GwtEvent<UsersListUpdatedHandler>{
	private static final Type<UsersListUpdatedHandler> TYPE = new Type<UsersListUpdatedHandler>();
	private ChangeType changeType;
	private UserAccountDetails userAccountDetails;
	
  public UsersListUpdatedEvent(ChangeType changeType, UserAccountDetails userAccountDetails) {
  	this.changeType = changeType;
  	this.userAccountDetails = userAccountDetails;
  }

  public static Type<UsersListUpdatedHandler> getType() {
    return TYPE;
  }

  @Override
  public com.google.gwt.event.shared.GwtEvent.Type<UsersListUpdatedHandler> getAssociatedType() {
    return TYPE;
  }
  
	@Override
  protected void dispatch(UsersListUpdatedHandler handler) {
		switch(changeType)
		{
		case Added: handler.onUserAdded(this);break;
		case Removed: handler.onUserRemoved(this);break;
		case Updated: handler.onUserUpdated(this);break;
		case AddFail: handler.onUserAddFailed(this);break;
		default: Log.error("Uknown change type: "+changeType);
		}
  }

	public UserAccountDetails getValue(){
		return userAccountDetails;
	}
}
